﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Hired
{
    public partial class qnaresults : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["search"] != null && Request.QueryString["category"] != null)
            {
                string searchQuery = Request.QueryString["search"].ToString();
                string category = Request.QueryString["category"].ToString();

                List<object> searchList = DBQuestion.searchQuestion(searchQuery, category);
                lblSearch.Text = searchQuery;
                lblCategory.Text = category;
                lblCount.Text = searchList.Count().ToString();

                if (searchList.Count() != 0)
                {
                    gvResults.DataSource = searchList;
                    gvResults.DataBind();
                }

                pnlValid.Visible = true;
                pnlInvalid.Visible = false;
            }
            else
            {
                pnlValid.Visible = false;
                pnlInvalid.Visible = true;
            }
        }

        protected string EvalLastAnswer(object LastAnswer)
        {
            if (LastAnswer != null)
            {
                return LastAnswer.ToString() + " by ";
            }
            else
            {
                return "-";
            }
        }

        protected string EvalLastPoster(object LastPoster)
        {
            if (LastPoster != null)
            {
                return LastPoster.ToString();
            }
            else
            {
                return "";
            }
        }
    }
}